package com.battery.web.controller.system.battery;

import java.util.List;

import com.battery.system.domain.BO.IncomeBO;
import com.battery.system.domain.VO.IncomeVO;
import com.battery.system.service.battery.IIncomeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.battery.common.annotation.Log;
import com.battery.common.enums.BusinessType;
import com.battery.system.domain.Income;
import com.battery.common.core.controller.BaseController;
import com.battery.common.core.domain.AjaxResult;
import com.battery.common.utils.poi.ExcelUtil;
import com.battery.common.core.page.TableDataInfo;

/**
 * 收益Controller
 *
 * @author battery
 * @date 2021-04-12
 */
@Controller
@RequestMapping("/system/income")
public class IncomeController extends BaseController {
    private String prefix = "system/income";

    @Autowired
    private IIncomeService incomeService;

    @RequiresPermissions("system:income:view")
    @GetMapping()
    public String income() {
        return prefix + "/income";
    }

    /**
     * 查询收益列表
     */
    @RequiresPermissions("system:income:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IncomeBO incomeBO) {
        startPage();
        List<IncomeVO> list = incomeService.selectIncomeVOList(incomeBO);
        return getDataTable(list);
    }

    /**
     * 导出收益列表
     */
//    @RequiresPermissions("system:income:export")
//    @Log(title = "收益", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(Income income) {
//        List<Income> list = incomeService.selectIncomeList(income);
//        ExcelUtil<Income> util = new ExcelUtil<Income>(Income.class);
//        return util.exportExcel(list, "income");
//    }

    /**
     * 新增收益
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存收益
     */
    @RequiresPermissions("system:income:add")
    @Log(title = "收益", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Income income) {
        return toAjax(incomeService.insertIncome(income));
    }

    /**
     * 修改收益
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Income income = incomeService.selectIncomeById(id);
        mmap.put("income", income);
        return prefix + "/edit";
    }

    /**
     * 修改保存收益
     */
    @RequiresPermissions("system:income:edit")
    @Log(title = "收益", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Income income) {
        return toAjax(incomeService.updateIncome(income));
    }

    /**
     * 删除收益
     */
    @RequiresPermissions("system:income:remove")
    @Log(title = "收益", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(incomeService.deleteIncomeByIds(ids));
    }
}
